
package com.epfresh.supplier.adapter;

import android.graphics.Color;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.epfresh.supplier.R;
import com.epfresh.supplier.entity.*;

import multitype.ItemViewBinder;
import multitype.OnRecyclerViewItemClickListener;
/*0,1,2*/
public class HomeBuyerTitleViewBinder
    extends ItemViewBinder<TitleBean, HomeBuyerTitleViewBinder.ViewHolder> implements View.OnClickListener{


    OnRecyclerViewItemClickListener onRecyclerViewItemClickListener;

    public OnRecyclerViewItemClickListener getOnRecyclerViewItemClickListener() {
        return onRecyclerViewItemClickListener;
    }

    public void setOnRecyclerViewItemClickListener(OnRecyclerViewItemClickListener onRecyclerViewItemClickListener) {
        this.onRecyclerViewItemClickListener = onRecyclerViewItemClickListener;
    }

    @NonNull
    @Override
    protected ViewHolder onCreateViewHolder(
            @NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        View view = inflater.inflate(R.layout.item_home_buyer_title, parent, false);
        return new ViewHolder(view);
    }


    @Override
    protected void onBindViewHolder(@NonNull ViewHolder holder, @NonNull TitleBean post) {


        holder.itemView.setTag(R.id.item_key_position,getPosition(holder));
        holder.itemView.setTag(R.id.item_key_status,post);
        holder.llCity.setOnClickListener(this);
        holder.llCategory.setOnClickListener(this);
        holder.tvCategory.setText(post.categoryName);
        Log.e("cityName","____________"+post.cityName);
        holder.tvCity.setText(post.cityName);
        holder.ivCategory.setImageResource(R.mipmap.select_down);
        holder.ivCity.setImageResource(R.mipmap.select_down);
        holder.tvCity.setTextColor(Color.parseColor("#434343"));
        holder.tvCategory.setTextColor(Color.parseColor("#434343"));
        if(post.upPosition == 1){
            holder.ivCity.setImageResource(R.mipmap.select_up);
            holder.tvCity.setTextColor(Color.RED);
        }else if(post.upPosition == 2){
            holder.ivCategory.setImageResource(R.mipmap.select_up);
            holder.tvCategory.setTextColor(Color.RED);
        }

        /*if(post == 1){//
            holder.ivCity.setImageResource(R.mipmap.select_up);
            holder.tvCity.setText();
        }else if(post == 2){
            holder.ivCity.setImageResource(R.mipmap.select_down);
            holder.ivCategory.setImageResource(R.mipmap.select_up);
        }else {
            holder.ivCategory.setImageResource(R.mipmap.select_down);
            holder.ivCity.setImageResource(R.mipmap.select_down);
        }*/
    }

    @Override
    public void onClick(View v) {
        if (onRecyclerViewItemClickListener != null){
            onRecyclerViewItemClickListener.onItemClick(v,0,null);
        }
    }


    static class ViewHolder extends RecyclerView.ViewHolder {

        private View llCategory, llCity;
        private ImageView ivCategory,ivCity;
        private TextView tvCategory,tvCity;


        ViewHolder(@NonNull View itemView) {
            super(itemView);
            llCategory = itemView.findViewById(R.id.ll_category);
            llCity = itemView.findViewById(R.id.ll_city);
            ivCategory = itemView.findViewById(R.id.iv_category);
            ivCity = itemView.findViewById(R.id.iv_city);
            tvCategory = itemView.findViewById(R.id.tv_category);
            tvCity = itemView.findViewById(R.id.tv_city);
        }
    }
}
